import http from '../../core/request'
import { Address } from './index.type'

// 地址列表
const getAddressList = (params: Address.Req.List) => {
  return http.get<Address.Res.List>('/address/list-my-self', params, { loading: true })
}
// 创建地址
const createAddress = (params: Address.Req.Create) => {
  console.log('createAddress', params)
  return http.post('/address/create-my-self', params, { loading: true })
}
// 默认设置
const setDefaultAddress = (params: Address.Req.SetDefault, id: string) => {
  return http.get(`/address/${id}/isDefault`, params, { loading: true })
}
// 更新地址
const updateAddress = (params: Address.Req.Update, id: string) => {
  return http.put(`/address/${id}/update-my-self`, params, { loading: true })
}
// 详情
const getAddressDetail = (id: string) => {
  return http.get<Address.Res.Detail>(`/address/${id}`, {}, { loading: true })
}
// 删除地址
const deleteAddress = (id: string) => {
  return http.delete(`/address/${id}/delete-my-self`, {}, { loading: true })
}
// 获取区域
const getRegions = () => {
  return http.get<Address.Res.Regions[]>('/regions', {}, { loading: false })
}
export default {
  getAddressList,
  createAddress,
  setDefaultAddress,
  updateAddress,
  deleteAddress,
  getRegions,
  getAddressDetail
}